﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace MusteriTakipProgrami
{
    public partial class MusteriAra : Form
    {

        private Form MusteriTakip;
        MusteriKayit musterikayit;
        //private Form MusteriGuncelle;
        MusteriGuncelle musteriguncelle;
        public MusteriAra()
        {
            InitializeComponent();
        }

        private void Ara_Btn_Click(object sender, EventArgs e)
        {

        }

        private void MusteriAra_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'mUSTERITAKIPDataSet3.MUSTERI' table. You can move, or remove it, as needed.
            this.mUSTERITableAdapter1.Fill(this.mUSTERITAKIPDataSet3.MUSTERI);
            // TODO: This line of code loads data into the 'mUSTERITAKIPDataSet.MUSTERI' table. You can move, or remove it, as needed.
            //  this.mUSTERITableAdapter.Fill(this.mUSTERITAKIPDataSet.MUSTERI);
            // TODO: This line of code loads data into the 'mUSTERITAKIPDataSet.MUSTERI' table. You can move, or remove it, as needed.
            //   this.mUSTERITableAdapter.Fill(this.mUSTERITAKIPDataSet.MUSTERI);

        }

        
        
        private void Ekle_Btn_Click(object sender, EventArgs e)
        {

            if (musterikayit != null)
                musterikayit.Dispose();
            musterikayit = new MusteriKayit();
            musterikayit.MdiParent = MusteriTakip;
            
            musterikayit.Show();

        }
        public static int id;
        public static string ad;
        public static string soyad;
        public static string adres;
        public static int ceptel;
        public static string eposta;
        public static DateTime dogumt;
        public static string musteritip;
        public static int telefon;
        
        public static string aciklama;
        //public static string 
        
            
        private void Guncelle_Btn_Click(object sender, EventArgs e)
        {
            id = Int32.Parse(this.dataGridView8.SelectedRows[0].Cells[0].Value.ToString());
            ad = this.dataGridView8.SelectedRows[0].Cells[1].Value.ToString();
            soyad = this.dataGridView8.SelectedRows[0].Cells[2].Value.ToString();
            adres = this.dataGridView8.SelectedRows[0].Cells[3].Value.ToString();
            ceptel = Int32.Parse(this.dataGridView8.SelectedRows[0].Cells[4].Value.ToString());
            eposta = this.dataGridView8.SelectedRows[0].Cells[5].Value.ToString();
            musteritip = this.dataGridView8.SelectedRows[0].Cells[7].Value.ToString();
            telefon = Int32.Parse(this.dataGridView8.SelectedRows[0].Cells[4].Value.ToString());
            aciklama = this.dataGridView8.SelectedRows[0].Cells[7].Value.ToString(); 

            //public static string 

            if (musteriguncelle != null)
                musteriguncelle.Dispose();
            musteriguncelle = new MusteriGuncelle();
            musteriguncelle.MdiParent = MusteriTakip;

            musteriguncelle.Show();
        }

        private void Sil_Btn_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("Silmek istediğinize emin misiniz?", "Uyarı", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                id = Int32.Parse(this.dataGridView8.SelectedRows[0].Cells[0].Value.ToString());

                if (this.dataGridView8.SelectedRows.Count > 0 && this.dataGridView8.SelectedRows[0].Index != this.dataGridView8.Rows.Count - 1)
                {
                   // SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=MUSTERITAKIP;Integrated Security=True");
                 



                    SqlConnection baglanti = new SqlConnection("Data Source=.;Initial Catalog=MUSTERITAKIP;Integrated Security=True");
            
                    this.dataGridView8.Rows.RemoveAt(this.dataGridView8.SelectedRows[0].Index);

                    string sorgu = "delete from MUSTERI where ID=@ID";
                    // Label kodlbl = (Label)this.dataGridView8.Rows.RemoveAt(this.dataGridView8.SelectedRows[0].Index);
                    // Response.Write(kodlbl.Text);
                    //SqlConnection baglanti = new SqlConnection(baglanti);
                    SqlCommand komut = new SqlCommand(sorgu, baglanti);
                    komut.Parameters.AddWithValue("@ID", id);
                    baglanti.Open();
                    komut.ExecuteNonQuery();
                    baglanti.Close();


                    // string silmesorgusu = "delete from MUSTERI where" + this.dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
                    //SqlCommand komut = new SqlCommand(silmesorgusu, baglanti);
                    //// komut.Parameters.AddWithValue("@kod", kodlbl.Text);
                    //baglanti.Open();
                    //komut.ExecuteNonQuery();
                    //baglanti.Close();

                }


            }
        }
        private void Cikis_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fillByToolStripButton_Click_1(object sender, EventArgs e)
        {
            try
            {
                this.mUSTERITableAdapter1.FillBy(this.mUSTERITAKIPDataSet3.MUSTERI, aDToolStripTextBox.Text, sOYADToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }
    }
}
